package com.example.testproj.jvm;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.example.testproj.R;
import com.example.testproj.utils.ThreadUtil;

public class JvmTestActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_jvm_test);
        ThreadUtil.getThreadUtil().submit(new Runnable() {
            @Override
            public void run() {
                _2MB_Data d1 = new _2MB_Data();
                _2MB_Data d2 = new _2MB_Data();
                d1.instance = d2;//1
                d2.instance = d1;//2

//                try {
//                    Thread.sleep(20*1000);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }

                d1 = null;
//                d2 = null;
//                System.gc();
                Log.d("qin","测试完成");
            }
        });

    }

    class _2MB_Data {
        public Object instance = null;
        private byte[] data = new byte[2 * 1024 * 1024];//用来占内存，测试垃圾回收

        @Override
        protected void finalize() throws Throwable {
            super.finalize();
            Log.d("qin", "finalize: 被回收"+this);
        }
    }
}
